#!/bin/bash
# Build and import git server image

set -euxo pipefail

upstream_ctx="${FLEET_E2E_CLUSTER-k3d-upstream}"

gitSrvImage=$( docker image ls -q nginx-git:test )

GIT_HTTP_PASSWORD=${GIT_HTTP_PASSWORD-foo}
if [ -n "${FORCE_GIT_SERVER_BUILD-}" -o -z "$gitSrvImage" ]; then
    cd e2e/assets/gitrepo
    docker build . -f Dockerfile.gitserver --build-arg passwd=$(openssl passwd $GIT_HTTP_PASSWORD) -t nginx-git:test
else
    echo "Git test server image already present. Skipping build."
fi

k3d image import nginx-git:test -m direct -c "${upstream_ctx#k3d-}"
